# logistics_page.py
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

class LogisticsPage:
    def __init__(self, driver):
        self.driver = driver
        self.url = 'http://example.com/logistics'
        self.order_number_input_locator = (By.ID, 'order-number-input')  # 订单号输入框定位器
        self.track_button_locator = (By.ID, 'track-button')  # 查询按钮定位器
        self.order_status_locator = (By.ID, 'order-status')  # 订单状态定位器
        self.delivery_status_locator = (By.ID, 'delivery-status')  # 物流状态定位器
        self.shipping_address_locator = (By.ID, 'shipping-address')  # 发货地址定位器
        self.delivery_address_locator = (By.ID, 'delivery-address')  # 收货地址定位器
        self.shipping_date_locator = (By.ID, 'shipping-date')  # 发货日期定位器
        self.delivery_date_locator = (By.ID, 'delivery-date')  # 预计送达日期定位器
        self.tracking_details_locator = (By.ID, 'tracking-details')  # 物流详情定位器
        self.back_to_orders_button_locator = (By.ID, 'back-to-orders-button')  # 返回订单列表按钮定位器
        self.error_message_locator = (By.ID, 'error-message')  # 错误消息定位器

    # 导航到物流查询页面
    def navigate(self):
        self.driver.get(self.url)

    # 输入订单号
    def enter_order_number(self, order_number):
        self.driver.find_element(*self.order_number_input_locator).send_keys(order_number)

    # 点击查询按钮
    def click_track_button(self):
        self.driver.find_element(*self.track_button_locator).click()

    # 获取订单状态
    def get_order_status(self):
        return self.driver.find_element(*self.order_status_locator).text

    # 获取物流状态
    def get_delivery_status(self):
        return self.driver.find_element(*self.delivery_status_locator).text

    # 获取发货地址
    def get_shipping_address(self):
        return self.driver.find_element(*self.shipping_address_locator).text

    # 获取收货地址
    def get_delivery_address(self):
        return self.driver.find_element(*self.delivery_address_locator).text

    # 获取发货日期
    def get_shipping_date(self):
        return self.driver.find_element(*self.shipping_date_locator).text

    # 获取预计送达日期
    def get_delivery_date(self):
        return self.driver.find_element(*self.delivery_date_locator).text

    # 获取物流详情
    def get_tracking_details(self):
        return self.driver.find_element(*self.tracking_details_locator).text

    # 点击返回订单列表按钮
    def click_back_to_orders_button(self):
        self.driver.find_element(*self.back_to_orders_button_locator).click()

    # 获取错误消息
    def get_error_message(self):
        return self.driver.find_element(*self.error_message_locator).text

    # 等待查询结果加载完成
    def wait_for_tracking_results(self):
        WebDriverWait(self.driver, 10).until(
            EC.presence_of_element_located(self.order_status_locator)
        )